<?php
/**
 * Edit / add a bookmark
 *
 * @package Bookmarks
 */
$title = elgg_extract('title', $vars, '');
$score = elgg_extract('score', $vars, '');
$golf_course_id = $score->golf_course_id;
$score_type = $score->score_type;
$holes_played = $score->holes_played;
$tee = $score->tee;

if($score_type == 1) {
	$score_details = elgg_get_golf_score_detail(array('golf_score_id' => $score->golf_score_id));
	$score_map = array();
	$score_total = 0;
	$score_in = 0;
	$score_out = 0;
	$esc_adjustment_score_map = array();
	$esc_adjustment_score_total = 0;
	$esc_adjustment_score_in = 0;
	$esc_adjustment_score_out = 0;
	foreach ($score_details as $score_detail) {
		$score_map['' . $score_detail->hole] = $score_detail->score;
		$esc_adjustment_score_map['' . $score_detail->hole] = $score_detail->esc_adjustment_score;
		$score_total += $score_detail->score;
		$esc_adjustment_score_total += $score_detail->esc_adjustment_score;
		if($score_detail->hole <= 9) {
			$score_out += $score_detail->score;
			$esc_adjustment_score_out += $score_detail->esc_adjustment_score;
		} else {
			$score_in += $score_detail->score;
			$esc_adjustment_score_in += $score_detail->esc_adjustment_score;
		}
	}
} else {
	$score_total = $score->total_score;
	$esc_adjustment_score_total = $score->esc_adjustment_total_score;
}

$golf_course = elgg_get_golf_course(array('golf_course_id' => $golf_course_id));
$golf_course = $golf_course[0];

if($score_type == 1) {
	$golf_course_cards = elgg_get_golf_course_card(array('golf_course_id' => $golf_course_id));
	$distance_map = array();
	$par_map = array();
	$distance_total = 0;
	$distance_in = 0;
	$distance_out = 0;
	$par_total = 0;
	$par_in = 0;
	$par_out = 0;
	foreach ($golf_course_cards as $golf_course_card) {
		$_distance = '';
		if($tee == 'gold') {
			$_distance = $golf_course_card->gold_tee_distance;
		} else if($tee == 'blue') {
			$_distance = $golf_course_card->blue_tee_distance;
		} else if($tee == 'white') {
			$_distance = $golf_course_card->white_tee_distance;
		} else if($tee == 'red') {
			$_distance = $golf_course_card->red_tee_distance;
		}
		$distance_map['' . $golf_course_card->hole] = $_distance;
		$par_map['' . $golf_course_card->hole] = $golf_course_card->par;
		$distance_total += $_distance;
		$par_total += $golf_course_card->par;
		if($golf_course_card->hole < 10) {
			$distance_out += $_distance;
			$par_out += $golf_course_card->par;
		} else {
			$distance_in += $_distance;
			$par_in += $golf_course_card->par;
		}
	}
} else {
	if($tee == 'gold') {
		$distance_total = $golf_course->gold_total;
	} else if($tee == 'blue') {
		$distance_total = $golf_course->blue_total;
	} else if($tee == 'white') {
		$distance_total = $golf_course->white_total;
	} else if($tee == 'red') {
		$distance_total = $golf_course->red_total;
	}
	$par_total = $golf_course->par_total;
}
$rating = 0;
$slope = 0;
if($tee == 'gold') {
	$rating = $golf_course->gold_course_rating;
	$slope = $golf_course->gold_course_slope;
} else if($tee == 'blue') {
	$rating = $golf_course->blue_course_rating;
	$slope = $golf_course->blue_course_slope;
} else if($tee == 'white') {
	$rating = $golf_course->white_course_rating;
	$slope = $golf_course->white_course_slope;
} else if($tee == 'red') {
	$rating = $golf_course->red_course_rating;
	$slope = $golf_course->red_course_slope;
}

$user_giud = elgg_get_logged_in_user_guid();
$golf_handicaps = elgg_get_golf_handicap(array('user_entity_id' => $user_giud));
$golf_handicap == null;
if(isset($golf_handicaps) && count($golf_handicaps) >= 1) {
	$golf_handicap = $golf_handicaps[0];
	$handicap_index = $golf_handicap->handicap_index;
	$handicap = elgg_golfscore_get_course_handicap($handicap_index,elgg_golfscore_get_course_slope($tee, $golf_course));
} else {
	$handicap = -1;
}
?>
<script type="text/javascript">
	
</script>
<h1><?php echo $title ?></h1>
<div id="__enter_course" style="margin-left: 5px;">
	<div style="margin-top: 20px;">
		<label class="elgg-golfscore-label-date"><?php echo elgg_echo('golfscore:view:date'); ?></label>
		<span class="elgg-golfscore-output-date"><?php echo $score->input_date; ?></span>
		<label class="elgg-golfscore-label-handicap"><?php echo elgg_echo('golfscore:handicap'); ?></label>
		<span><?php if($handicap >= 0) echo $handicap; else echo '--';?></span>
	</div>
	<div style="margin-top: 5px;">
		<label class="elgg-golfscore-label-course"><?php echo elgg_echo('golfscore:view:course'); ?></label>
		<span><?php echo $golf_course->course_name; ?></span>
	</div>
	<div style="margin-top: 5px;">
		<label class="elgg-golfscore-label-tee">
			<div class="elgg-golfscore-icon-tee-<?php echo getTeeName($score->tee, $golf_course); ?>">&nbsp;</div>
			<?php echo elgg_echo('golfscore:view:tee'); ?>
		</label>
		<span class="elgg-golfscore-output-tee"><?php echo elgg_echo("golfscore:tee:" . getTeeName($score->tee, $golf_course)); ?></span>
		<label class="elgg-golfscore-label-rating"><?php echo elgg_echo('golfscore:view:rating'); ?></label>
		<span class="elgg-golfscore-output-rating"><?php echo $score->course_rating; ?></span>
		<label class="elgg-golfscore-label-slope"><?php echo elgg_echo('golfscore:view:slope'); ?></label>
		<span><?php echo $score->course_slope; ?></span>
	</div>
	<div style="margin-top: 10px;">
		<div class="rowHoleBox" style="border-top:1px solid #ddd;background-color:#eeeeee;">
			<div class="totalHoleBox"><?php echo elgg_echo('golfscore:view:total'); ?></div>
			<?php if($score_type == 1) {?>
			<div class="totalHoleBox"><?php echo elgg_echo('golfscore:view:in'); ?></div>
			<div class="editHoleBox">18</div>
			<div class="editHoleBox">17</div>
			<div class="editHoleBox">16</div>
			<div class="editHoleBox">15</div>
			<div class="editHoleBox">14</div>
			<div class="editHoleBox">13</div>
			<div class="editHoleBox">12</div>
			<div class="editHoleBox">11</div>
			<div class="editHoleBox">10</div>
			<div class="totalHoleBox"><?php echo elgg_echo('golfscore:view:out'); ?></div>
			<div class="editHoleBox">9</div>
			<div class="editHoleBox">8</div>
			<div class="editHoleBox">7</div>
			<div class="editHoleBox">6</div>
			<div class="editHoleBox">5</div>
			<div class="editHoleBox">4</div>
			<div class="editHoleBox">3</div>
			<div class="editHoleBox">2</div>
			<div class="editHoleBox">1</div>
			<?php }?>
			<div class="labelHoleBox"><?php echo elgg_echo('golfscore:view:hole'); ?></div>
		</div>
		<div class="rowHoleBox" style="background-color:#ffffff;" id="__distance">
			<div id="__distance_total" class="totalHoleBox"><?php echo $distance_total; ?></div>
			<?php if($score_type == 1) {?>
			<div id="__distance_out" class="totalHoleBox"><?php echo $distance_out; ?></div>
			<div id="__distance_18" class="editHoleBox"><?php echo $distance_map[18]; ?></div>
			<div id="__distance_17" class="editHoleBox"><?php echo $distance_map[17]; ?></div>
			<div id="__distance_16" class="editHoleBox"><?php echo $distance_map[16]; ?></div>
			<div id="__distance_15" class="editHoleBox"><?php echo $distance_map[15]; ?></div>
			<div id="__distance_14" class="editHoleBox"><?php echo $distance_map[14]; ?></div>
			<div id="__distance_13" class="editHoleBox"><?php echo $distance_map[13]; ?></div>
			<div id="__distance_12" class="editHoleBox"><?php echo $distance_map[12]; ?></div>
			<div id="__distance_11" class="editHoleBox"><?php echo $distance_map[11]; ?></div>
			<div id="__distance_10" class="editHoleBox"><?php echo $distance_map[10]; ?></div>
			<div id="__distance_out" class="totalHoleBox"><?php echo $distance_in; ?></div>
			<div id="__distance_9" class="editHoleBox"><?php echo $distance_map[9]; ?></div>
			<div id="__distance_8" class="editHoleBox"><?php echo $distance_map[8]; ?></div>
			<div id="__distance_7" class="editHoleBox"><?php echo $distance_map[7]; ?></div>
			<div id="__distance_6" class="editHoleBox"><?php echo $distance_map[6]; ?></div>
			<div id="__distance_5" class="editHoleBox"><?php echo $distance_map[5]; ?></div>
			<div id="__distance_4" class="editHoleBox"><?php echo $distance_map[4]; ?></div>
			<div id="__distance_3" class="editHoleBox"><?php echo $distance_map[3]; ?></div>
			<div id="__distance_2" class="editHoleBox"><?php echo $distance_map[2]; ?></div>
			<div id="__distance_1" class="editHoleBox"><?php echo $distance_map[1]; ?></div>
			<?php }?>
			<div class="labelHoleBox"><?php echo elgg_echo('golfscore:view:distance'); ?></div>
		</div>
		<div class="rowHoleBox" style="background-color:#eeeeee;" id="__par">
			<div id="__par_total" class="totalHoleBox"><?php echo $par_total; ?></div>
			<?php if($score_type == 1) {?>
			<div id="__par_in" class="totalHoleBox"><?php echo $par_in; ?></div>
			<div id="__par_18" class="editHoleBox"><?php echo $par_map[18]; ?></div>
			<div id="__par_17" class="editHoleBox"><?php echo $par_map[17]; ?></div>
			<div id="__par_16" class="editHoleBox"><?php echo $par_map[16]; ?></div>
			<div id="__par_15" class="editHoleBox"><?php echo $par_map[15]; ?></div>
			<div id="__par_14" class="editHoleBox"><?php echo $par_map[14]; ?></div>
			<div id="__par_13" class="editHoleBox"><?php echo $par_map[13]; ?></div>
			<div id="__par_12" class="editHoleBox"><?php echo $par_map[12]; ?></div>
			<div id="__par_11" class="editHoleBox"><?php echo $par_map[11]; ?></div>
			<div id="__par_10" class="editHoleBox"><?php echo $par_map[10]; ?></div>
			<div id="__par_out" class="totalHoleBox"><?php echo $par_out; ?></div>
			<div id="__par_9" class="editHoleBox"><?php echo $par_map[9]; ?></div>
			<div id="__par_8" class="editHoleBox"><?php echo $par_map[8]; ?></div>
			<div id="__par_7" class="editHoleBox"><?php echo $par_map[7]; ?></div>
			<div id="__par_6" class="editHoleBox"><?php echo $par_map[6]; ?></div>
			<div id="__par_5" class="editHoleBox"><?php echo $par_map[5]; ?></div>
			<div id="__par_4" class="editHoleBox"><?php echo $par_map[4]; ?></div>
			<div id="__par_3" class="editHoleBox"><?php echo $par_map[3]; ?></div>
			<div id="__par_2" class="editHoleBox"><?php echo $par_map[2]; ?></div>
			<div id="__par_1" class="editHoleBox"><?php echo $par_map[1]; ?></div>
			<?php }?>
			<div class="labelHoleBox"><?php echo elgg_echo('golfscore:view:par'); ?></div>
		</div>
		<div class="rowHoleBox" style="background-color:#ffffff;">
			<div class="totalHoleBox"><?php echo $score_total; ?></div>
			<?php if($score_type == 1) {?>
			<div class="totalHoleBox"><?php echo $score_out; ?></div>
			<div class="editHoleBox"><?php echo $score_map[18]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[17]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[16]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[15]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[14]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[13]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[12]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[11]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[10]; ?></div>
			<div class="totalHoleBox"><?php echo $score_in; ?></div>
			<div class="editHoleBox"><?php echo $score_map[9]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[8]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[7]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[6]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[5]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[4]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[3]; ?></div>
			<div class="editHoleBox"><?php echo $score_map[2]; ?></div>
			<div class="editHoleBox" style=""><?php echo $score_map[1]; ?></div>
			<?php }?>
			<div class="labelHoleBox"><?php echo elgg_echo('golfscore:view:score'); ?></div>
		</div>
		<div class="rowHoleBox" style="background-color:#eeeeee;">
			<div class="totalHoleBox"><?php echo $esc_adjustment_score_total; ?></div>
			<?php if($score_type == 1) {?>
			<div class="totalHoleBox"><?php echo $esc_adjustment_score_out; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[18]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[17]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[16]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[15]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[14]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[13]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[12]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[11]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[10]; ?></div>
			<div class="totalHoleBox"><?php echo $esc_adjustment_score_in; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[9]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[8]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[7]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[6]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[5]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[4]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[3]; ?></div>
			<div class="editHoleBox"><?php echo $esc_adjustment_score_map[2]; ?></div>
			<div class="editHoleBox" style=""><?php echo $esc_adjustment_score_map[1]; ?></div>
			<?php }?>
			<div class="labelHoleBox"><?php echo elgg_echo('golfscore:view:esc_adjustment_score'); ?></div>
		</div>
	</div>
</div>
<?php
	echo '<div class="elgg-foot" style="margin: 5px 0px 0px 5px;">';
	echo elgg_view('output/url', array(
			'href' => "golfscore/edit?golf_score_id=" . $score->golf_score_id,
			'text' => elgg_echo('golfscore:edit'),
			'is_trusted' => true,
			'class' => 'btnScore',
		));
	echo '&nbsp;&nbsp;&nbsp;';
	echo elgg_view('output/url', array(
			'href' => "action/golfscore/delete?golf_score_id=" . $score->golf_score_id,
			'text' => elgg_echo('golfscore:delete'),
			'is_trusted' => true,
			'is_action' => true,
			'class' => 'btnScore btnDelete',
	));
	echo '</div>';
?>